'''
Created on 2011-06-22

@author: Andrew Roth
'''
import pysam

from python_base_counter import BaseCounter
from bam_counter.base_counter import BaseCounter as FastBaseCounter

def pure_python():
    file_name = "/share/data/VBA0038/VBA0038.normal.bam"

    counter = BaseCounter(pysam.Samfile(file_name, 'rb'))
    
    for row in counter.iter_ref('MT'):
        pass
    
def cython_python():
    file_name = "/share/data/VBA0038/VBA0038.normal.bam"

    counter = FastBaseCounter(pysam.Samfile(file_name, 'rb'))

    for row in counter.iter_ref('MT'):
        pass
#        if sum(row.counts.values()) > 10:
#            print row

def visual_test():
    file_name = "/share/data/VBA0038/VBA0038.normal.bam"

    counter = FastBaseCounter(pysam.Samfile(file_name, 'rb'))
    
    for row in counter.iter_ref('1'):
        if sorted(row.counts.values())[2] >= 30:
            print row
            
if __name__ == "__main__":
#    cython_python()
#    visual_test()

#    import pstats, cProfile
#    
#    cProfile.runctx("cython_python()", globals(), locals(), "Profile.prof")
#    
#    s = pstats.Stats("Profile.prof")
#    s.strip_dirs().sort_stats("time").print_stats()
    
#    import line_profiler
#    
#    from bam_counter.cbam import parse_pileup_column
#    
#    profiler = line_profiler.LineProfiler(FastBaseCounter.iter_ref)
#    
#    run_str = "cython_python()"
#    
#    profiler.run( run_str )
#    profiler.print_stats()
    
    import timeit
    
    python = "pure_python()"
    cython = "cython_python()"
    
    t = timeit.Timer(python, "from __main__ import pure_python")
    print t.timeit(10)
    
    t = timeit.Timer(cython, "from __main__ import cython_python")
    print t.timeit(10)
